   var adUnit;
   var marker;
   var infoWindow;
   var geocoder = new google.maps.Geocoder();
   var map = null;
   var lat;
   var lon;

   function initialize() {
	 
      var mapOptions = {
	 zoom: 16,
	 mapTypeId: google.maps.MapTypeId.ROADMAP,
	 streetViewControl: false,
	 panControl: false,
         mapTypeControl: true, 
         mapTypeControlOptions: { 
          style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, 
          position: google.maps.ControlPosition.BOTTOM_CENTER
         },
         zoomControl: true,
         zoomControlOptions: {
          style: google.maps.ZoomControlStyle.SMALL,
          position: google.maps.ControlPosition.LEFT_CENTER
         }
      };
  
     map = new google.maps.Map(document.getElementById('map'), mapOptions);
     var adUnitDiv = document.createElement('div');
     var adsense = "ca-pub-3152670624293746";
	   
     var adUnitOptions = {
	 format: google.maps.adsense.AdFormat.BUTTON,
         position: google.maps.ControlPosition.RIGHT_BOTTOM,
         publisherId: adsense,
         map: map,
         visible: true
     };

     var adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);

     lat = 37.41954708018655;
     lon = -122.08398342132568;
	 
     if(navigator.geolocation) {
	 navigator.geolocation.getCurrentPosition(function(position) {
	  lat = position.coords.latitude;
          lon = position.coords.longitude;
	 });
     }
	 
     var latLng = new google.maps.LatLng(lat, lon);
     map.setCenter(latLng);
     marker = new google.maps.Marker({
	 position: latLng,
	 title: 'Drag this pin to another location',
	 animation: google.maps.Animation.DROP,
	 map: map,
	 draggable: true
     });
	
     infoWindow = new google.maps.InfoWindow({
	content: "<div class='place'>Drag this pin anywhere on the Google Map to know the approximate address of that point.</div>"
     });  

     infoWindow.open(map, marker);
     google.maps.event.addListener(marker, 'dragend', function() {
	geocoder.geocode({latLng: marker.getPosition()}, function(responses) {
	  if (responses && responses.length > 0) {
		infoWindow.setContent(
		   "<div class='place'>" + responses[0].formatted_address 
		   + "<br /> <small>"
		   + "Latitude: "  + marker.getPosition().lat() + "<br>" 
		   + "Longitude: " + marker.getPosition().lng() + "</small></div>"
		 );
		 infoWindow.open(map, marker);
	} else {
		alert('Sorry but Google Maps was unable to determine the address of this location.');
	}
     });
     map.panTo(marker.getPosition());
   });
	
	google.maps.event.addListener(marker, 'dragstart', function() {
		infoWindow.close(map, marker);
	});
  }
      
  google.maps.event.addDomListener(window, 'load', initialize);

    function showAddress(address) {
      if (geocoder) {
	geocoder.geocode({ 'address': address }, function(results, status) { 
       		if (status == google.maps.GeocoderStatus.OK) { 
                       if(results[0].geometry.location_type == "ROOFTOP")
                        map.setZoom(18);
                       else
                        map.setZoom(14);
                       map.setCenter(results[0].geometry.location); 
                       marker.setPosition(results[0].geometry.location);
                       infoWindow.setContent(
                          "<div class='place'>" + results[0].formatted_address
                          + "<br /> <small>"
                          + "Latitude: " + marker.getPosition().lat() + "<br />"
                          + "Longitude: " + marker.getPosition().lng() + "</small></div>"
                        );

                       infoWindow.open(map, marker);
                 } else { 
                alert("We're sorry but '" + address + "' cannot be found on Google Maps. Please try another address.");
            } 
        });
      }
    }
